You can use the Picture Utilities routines to gather extensive information about pictures and to gather color information about pixel maps. You use the GetPictInfo function to gather information about a single picture, and you use the GetPixMapInfo function to gather color information about a single pixel map or bitmap. Each of these functions returns color and resolution information in a PictInfo record (described on PictInfo ). A PictInfo record can also contain information about the drawing objects, fonts, and comments in a picture.
You can also survey multiple pictures, pixel maps, and bitmaps for this information. Use the NewPictInfo function to begin collecting pictures, pixel maps, and bitmaps for your survey. You also use NewPictInfo to specify how you would like the color, comment, and font information for the survey returned to you.
To add the information for a picture to your survey, use the RecordPictInfo function. To add the information for a pixel map or a bitmap to your survey, use the RecordPixMapInfo function. The RetrievePictInfo function collects the information about the pictures, pixel maps, and bitmaps that you have added to your survey. The RetrievePictInfo function returns this information in a PictInfo record.
For example, to use the ColorSync Utilities to match the colors in a single picture to an output device such as a color printer, an application might find it useful to find the CMBeginProfile picture comment, which marks the beginning of a color profile in a Picture record. (Color profiles and the ColorSync Utilities are described in Inside Macintosh: Advanced Color Imaging .) Listing 7-12 shows an application-defined routine, called MyGetPICTProfileCount , that uses GetPictInfo to record comments in a CommentSpec record (which is described on CommentSpec ). The MyGetPICTProfileCount routine uses the CommentSpec record to determine whether any color profiles are included in the picture as picture comments.
Listing 12 Looking for color profile comments in a picture
FUNCTION MyGetPICTProfileCount (hPICT: PicHandle; VAR count: Integer): OSErr;
VAR
err: OSErr;
thePICTInfo: PictInfo;
verb: Integer;
colorsRequested: Integer;
colorPickMethod: Integer;
version: Integer;
pCommentSpec: CommentSpecPtr;
i: Integer;
BEGIN
count := 0;
verb := recordComments;
colorsRequested := 0;
colorPickMethod := systemMethod;
version := 0;
err := GetPictInfo(hPICT, thePICTInfo, verb, colorsRequested,
colorPickMethod, version);
IF ((err = noErr) AND (thePICTInfo.commentHandle <> NIL)) THEN
BEGIN
pCommentSpec := thePICTInfo.commentHandle^;
FOR i := 1 TO thePICTInfo.uniqueComments DO
BEGIN
IF (pCommentSpec^.ID = CMBeginProfile) THEN
BEGIN
count := pCommentSpec^.count;
LEAVE;
END;
pCommentSpec :=
CommentSpecPtr(ORD4(pCommentSpec)+Sizeof(CommentSpec));
END;
{clean up allocations made by GetPictInfo}
DisposeHandle(Handle(thePICTInfo.commentHandle));
END;
MyGetPICTProfileCount := err;
END;
If you want information about the colors of a picture or pixel map, you indicate to the Picture Utilities how many colors (up to 256) you want to know about, what method to use for selecting the colors, and whether you want the selected colors returned in a Palette record or ColorTable record.
The Picture Utilities provide two color-picking methods: one that gives you the most frequently used colors and one that gives you the widest range of colors. Each has advantages in different situations. For example, suppose the picture of a forest image contains 400 colors, of which 300 are greens, 80 are browns, and the rest are a scattering of golden sunlight effects. If you ask for the 250 most used colors, you will probably receive all greens. If you ask for a range of 250 colors, you will receive an assortment stretching from the greens and golds to the browns, including colors in between that might not actually appear in the image. You can also supply a color-picking method of your own, as described in "Application-Defined Routines," .
Your application can then use the color information returned by the Picture Utilities in conjunction with the Palette Manager to provide the best selection of colors for displaying the picture on an 8-bit indexed device.
When you ask for color information about a picture, the Picture Utilities take into account only the version 2 and extended version 2 picture opcodes RGBFgCol , RGBBkCol , BkPixPat , PnPixPat , FillPixPat , and HiliteColor (as well as pixel map or bitmap data). Each occurrence of these opcodes is treated as one pixel, regardless of the number and sizes of the objects drawn with that color. If you need an accurate set of colors from a complex picture, create an image of the picture in an offscreen graphics world and call the GetPixMapInfo function to obtain color information about that pixel map for that graphics world.